package com.pew.tasktimer.domain;

import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class TaskTest {

	Logger cLogger = Logger.getLogger(TaskTest.class);
	
	private Task cTask = null;
	private boolean cbStartRan = false;
	
	@BeforeClass
	public void setUpTask() {
		BasicConfigurator.configure();
		cTask = new Task();
		
	}
	
	@AfterMethod
	public void printIt() {
		if (cLogger.isDebugEnabled()) {
			cLogger.debug("Contents: " + cTask.toString());
		}
	}
	
  @Test
  public void fillInStartInfo_p() {
    throw new RuntimeException("Test not implemented");
  }

  @Test
  public void fillInStopInfo_p() {
    throw new RuntimeException("Test not implemented");
  }

  @Test
  public void isRunning() {
	cTask = new Task();
	assert (cTask.isRunning() == false);
	
    cTask.startTimer();
    assert (cTask.isRunning() == true);
    
    cTask.stopTimer();
	assert (cTask.isRunning() == false);
	
	
  }

  @Test
  public void startTimer() {
	  long lTime = System.currentTimeMillis();
	  cTask.startTimer();
	  assert (lTime <= cTask.clStartTime);
	  assert (lTime >= cTask.clStopTime);
	  cbStartRan = true;
  }

  @Test
  public void stopTimer() {
	  long llTime = System.currentTimeMillis();
	  if (cbStartRan == false)
	  {
		  startTimer();
	  }
	  cTask.stopTimer();
	  
	  
	  assert (llTime > cTask.clStartTime);
	  assert (llTime <= cTask.clStopTime);
  }
}
